package com.xl.optimize.first;

import java.util.Arrays;
import java.util.List;
import java.util.function.Function;

/**
 * 提取重复代码
 */
public class ExtractDuplicateCode {

    public static void main(String[] args) {
        List<String> names = Arrays.asList("Alice","Bob","Charlie","David","TianLuo");

        /*System.out.println("Uppercase Names:");
        for (String name : names) {
            String uppercaseName = name.toUpperCase();
            System.out.println(uppercaseName);
        }
        System.out.println("Lowercase Names:");
        for(String name : names) {
            String lowercaseName = name.toLowerCase();
            System.out.println(lowercaseName);
        }*/

        processNames(names, String::toUpperCase, "Uppercase");
        processNames(names, String::toLowerCase, "Lowercase");
    }

    public static void processNames(List<String> names, Function<String, String> nameProcessor, String processType) {
        System.out.println(processType + " Names:");
        for (String name : names) {
            String processedName = nameProcessor.apply(name);
            System.out.println(processedName);
        }
    }
}
